var localdata=[
        {
        "id":"fav0",
        "webname":"hao123",
        "webaddress":"https://www.hao123.com/"
        },
        {
            "id":"fav1",
            "webname":"百度搜索",
            "webaddress":"http://www.baidu.com"
        },
        {
            "id":"fav2",
            "webname":"百度新新闻",
            "webaddress":"http://news.baidu.com/"
        },
        {
            "id":"fav3",
            "webname":"百度学术",
            "webaddress":"http://xueshu.baidu.com/"
        }
];


var decorateEle = function(item){
    return '<li><a id="'+item.id+'">'+item.webname+'</a></li>';
}

//dom ready 后，给id="favouritesApps" 插入收藏按钮等
$(document).ready(function(){

    var favStart = '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button><ul class="dropdown-menu">';
    var favItems = '';//'<li><a href="#">下拉链接 1</a></li>'
    var favEnd = '</ul></div>';

    for (let index = 0; index < localdata.length; index++) {
        favItems = favItems + decorateEle(localdata[index]);
    }

    $("#favouritesApps").append(favStart + favItems + favEnd);

    for(var i=0;i<localdata.length;i++){


        $("#"+localdata[i].id).click(function(target,event){

            //console.log(target.currentTarget.id);
            //console.log(target.currentTarget.id.slice(3));
            console.log("Browser will goto "+localdata[target.currentTarget.id.slice(3)].webaddress);
        })
    }


});